package com.ling.pl.autoproject.builder.model;

import com.ling.pl.autoproject.builder.utils.AutoProjectUtils;

import java.util.ArrayList;
import java.util.List;

public class OneToManyPojo {
    POJOClass one;
    String module;
    String system;
    List<POJOClass> many = new ArrayList<POJOClass>();
    List<POJOClass> ones = new ArrayList<POJOClass>();

    public POJOClass getOne() {
        return one;
    }

    public void setOne(POJOClass one) {
        this.one = one;
    }

    public void setOne(Class class_) {
        this.one = AutoProjectUtils.revertClass2Pojo(class_);
    }

    public List<POJOClass> getMany() {
        return many;
    }

    public void setMany(List<POJOClass> many) {
        this.many = many;
    }

    public void addMany(POJOClass pojoClass) {
        if (pojoClass.getRelation() == null) {
            pojoClass.setRelation(RelationType.MANY_DEFAULT);
        }
        if (many == null) {
            many = new ArrayList<POJOClass>();
        }
        many.add(pojoClass);
    }

    public void addMany(Class class1, String relation) {
        POJOClass pojoClass = AutoProjectUtils.revertClass2Pojo(class1);
        pojoClass.setRelation(relation);
        addMany(pojoClass);
    }

    public void addMany(Class class1) {
        addMany(class1, RelationType.MANY_DEFAULT);
    }

    public void addOne(POJOClass pojoClass) {
        if (ones == null) {
            ones = new ArrayList<POJOClass>();
        }
        if (pojoClass.getRelation() == null) {
            pojoClass.setRelation(RelationType.MANY_DEFAULT);
        }
        ones.add(pojoClass);
    }

    public void addOne(Class class1) {
        POJOClass pojoClass = AutoProjectUtils.revertClass2Pojo(class1);
        pojoClass.setRelation(RelationType.ONE_DEFAULT);
        addOne(pojoClass);
    }

    public void addOne(Class class1, String relation) {
        POJOClass pojoClass = AutoProjectUtils.revertClass2Pojo(class1);
        pojoClass.setRelation(relation);
        addOne(pojoClass);
    }

    public List<POJOClass> getOnes() {
        return ones;
    }

    public void setOnes(List<POJOClass> ones) {
        this.ones = ones;
    }

    public int entitySize() {
        return 1 + many.size() + ones.size();
    }

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    public String getSystem() {
        return system;
    }

    public void setSystem(String system) {
        this.system = system;
    }
}
